<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>分类管理</title>
    <link rel="stylesheet" type="text/css" href="http://localhost/e-shop/xiangqu/Static/hdjs/hdjs.css">
    <script type="text/javascript" charset="utf-8" src="http://localhost/e-shop/xiangqu/Static/ueditor1_4_3/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="http://localhost/e-shop/xiangqu/Static/ueditor1_4_3/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="utf-8" src="http://localhost/e-shop/xiangqu/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="http://localhost/e-shop/xiangqu/Static/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="http://localhost/e-shop/xiangqu/Static/uploadify/jquery.uploadify.min.js"></script>
	<link href="http://localhost/e-shop/xiangqu/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<style type="text/css">
		#detail,#server{
			margin: 0 auto;
		}
		#photo-list li,#photo-list2 li{
			list-style: none;
			float: left;
			margin-right: 20px;
		}
		.adds{
			/*padding-right: 50px;*/
		}
		.wrap select{
			width: 220px;
			height: 30px;
		}
		.wrap input{
			width: 200px;
			height: 30px;
		}
		
	</style>
	<script type="text/javascript">
		$(function(){
			$('select[name=category_cid]').change(function(){
				//获取选择中的分类中的tid
				var tid = $(':selected').attr('tid');
				$.ajax({
					type:"post",
					url:"<?php echo U('getAttrSpec');?>",
					dataType:'json',
					data:{tid:tid},
					success:function(phpData){
						//加载属性和规格
						//属性
						var attr = '';
						//规格
						var spec = '';
						$.each(phpData,function(k,v){
							//如果是属性
							if(v.class==1){
								attr += '<tr><td width="245">'+v.taname+'</td><td width="300"><select name="attr['+v.taid+']"><option value="0">--请选择--</option>'
								$.each(v.tavalue,function(kk,vv){
									attr += '<option value="'+vv+'">' + vv + '</option>'
								})
								attr += '</select></td><td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请选择'+v.taname+'</td></tr>'
							}else{
								//如果是规格
								spec += '<tr><td width="245">'+v.taname+'</td><td><select name="spec['+v.taid+'][tavalue][]"><option value="0">--请选择--</option>'
								$.each(v.tavalue,function(kk,vv){
									spec += '<option value="'+vv+'">'+vv+'</option>'
								})
								spec += '</select></td><td style="color: #888888;" width="120"><span style="color: red;">*&nbsp;&nbsp;</span>请选择'+v.taname+'</td><td>附加价格<input name="spec['+v.taid+'][add][]"></td><td style="color: #888888;">请添加附件价格</td><td><a href="javascript:;" class="adds hd-btn hd-btn-success hd-btn-xm">增加一项</a></td></tr>'
							}
							
						})
						$('#attr').html(attr);
						$('#spec').html(spec);
						
						
						
					}
				});
				
			})
			
			
			//处理****删除图片
			$('.del-img').live('click',function(){
				var li = $(this).parents('li');
				var path = li.attr('path');
				$.ajax({
					type:"post",
					url:"<?php echo U('delImg');?>",
					data:{path:path},
					success:function(data){
						li.remove();
					}
					
				})
				
			})
			
//			//添加规格项
//			$('.adds').live('click',function(){
//				
//				var addtr = $(this).parents('tr').clone();
//				$(this).parents('tr').after(addtr);
//				
//			})

			//添加规格项
			$('.adds').live('click',function(){
				var addtr = $(this).parents('tr').clone();
				$(addtr).find('td').eq(5).html('<a href="javascript:;" class="removes hd-btn hd-btn-danger hd-btn-xm">删除此项</a>');
				$(this).parents('tr').after(addtr);
			})
			
			//删除规格
			$('.removes').live('click',function(){
				
				$(this).parents('tr').remove();
			})
			
			
			
		})
		
		
		
	</script>
</head>
<body>
<div class="wrap">
    <div class="hd-title-header">添加品牌</div>
    <form action="" method="post" class="form-inline hd-form" enctype="multipart/form-data" >
			<table class='hd-table hd-table-form hd-table-list'>
				<thead>
					<tr>
						<th colspan="3" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td width="248">所属分类</td>
						<td width="300">
							<select name="category_cid">
								<option value="0">-请选择-</option>
								<?php foreach ($cate as $k=>$v){?>
									<option value="<?php echo $v['cid'];?>" tid="<?php echo $v['Type_tid'];?>"><?php echo $v['_name'];?></option>
								<?php }?>
							</select>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>选择分类</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td width="300">
							<select name="brand_bid">
								<option value="0">-请选择-</option>
								<?php foreach ($brand as $k=>$v){?>
									<option value="<?php echo $v['bid'];?>"><?php echo $v['bname'];?></option>
								<?php }?>
							</select>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请选择品牌</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname'/>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请填写商品名称</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='gunit' value='件'/>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请填写商品计数单位</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice'/>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请填写市场价格（单位：人民币）</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice'/>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请填写商城价格（单位：人民币）</td>
					</tr>
					<tr class="info">
						<td>货品单号</td>
						<td>
							<input type="text" name='gnumber'/>
						</td>
						<td style="color: #888888;"><span style="color: red;">*&nbsp;&nbsp;</span>请填写货品单号</td>
					</tr>
					
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click'/>
						</td>
						<td style="color: #888888;">请填写点击次数</td>
					</tr>
				</tbody>
			</table>
			
			<p class="hd-title-header" style="text-align: center;">商品属性</p>
			<table class="hd-table hd-table-form hd-table-list" id='attr'>

			</table>
			<p class="hd-title-header" style="text-align: center;">商品规格</p>
			<table class="hd-table hd-table-form hd-table-list" id='spec'>
				
			</table>
			<p class="hd-title-header" style="text-align: center;">列表图</p>
			<table class='hd-table hd-table-form hd-table-list' border="0">
				<tr class="info">
					<td width="100" height="120">上传图片</td>
					<td width="400">
				<input id="file" type="file" multiple="true" name="thumb">
	            <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
	            <script type="text/javascript">
	                $(function() {
	                    $('#file').uploadify({
	                        'formData'     : {//POST数据
	                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                        },
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : 'http://localhost/e-shop/xiangqu/Static/uploadify/uploadify.swf',
	                        'uploader' : '<?php echo U("upload");?>',//执行控制器上的上传类
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 1000,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 0.2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                            var imageUrl = data.image?data.url:'http://localhost/e-shop/xiangqu/Static/image/default.png';
	                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-img'>X</a><input type='hidden' name='picture' value='"+data.path+"'></li>";
	                            $("#photo-list").append(li);
	                        }
	                    });
	                });
	            </script>
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>
			
			<p class="hd-title-header" style="text-align: center;">商品图册</p>
			<table class='hd-table hd-table-form hd-table-list'>
				<tr class="info">
					<td width="100" height="100">上传图片</td>
					<td width="400">
				<input id="pic" type="file" multiple="true" name="thumb">
	            <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
	            <script type="text/javascript">
	                $(function() {
	                    $('#pic').uploadify({
	                        'formData'     : {//POST数据
	                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                        },
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : 'http://localhost/e-shop/xiangqu/Static/uploadify/uploadify.swf',
	                        'uploader' : '<?php echo U("upload");?>',//执行控制器上的上传类
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 1000,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 0.2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                            var imageUrl = data.image?data.url:'http://localhost/e-shop/xiangqu/Static/image/default.png';
	                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-img'>X</a><input type='hidden' name='pic_goods[]' value='"+data.path+"'></li>";
	                            $("#photo-list2").append(li);
	                        }
	                    });
	                });
	            </script>
					</td>
					<td id='photo-list2'></td>
				</tr>
			</table>
			
			<p class="hd-title-header" style="text-align: center;">商品详细</p>
			<table class='hd-table hd-table-form hd-table-list' border="0">
				<tr class="hide info">
					<td>
						<script id="detail" type="text/plain" style="width:1000px;height:300px;" name="gdetail"></script>
					  	<script>
					        var ue = UE.getEditor('detail');
					    </script>
					</td>
				</tr>
			</table>
			
			<p class="hd-title-header" style="text-align: center;">售后服务</p>
			<table class='table hd-table hd-table-list'>
				<tr class="hide info">
					<td>
						<script id="server" type="text/plain" style="width:1000px;height:300px;" name="service"></script>
				  		<script>
				        	var ue = UE.getEditor('server');
				   		</script>
					</td>
				</tr>
			</table>
			
			
			
			
			
			
			
			
        <div class="position-bottom">
            <input type="submit" class="hd-btn hd-btn-success" value="添加"/>
        </div>
    </form>
</div>
</body>
</html>